package com.queclink.ycm.entity;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.queclink.ycm.common.utils.HexUtils;
import com.queclink.ycm.common.utils.StringUtil;

/**
 * @author jim.li
 * @email jim.li@queclink.com
 * @date 2024-06-28 14:23:00
 */
public class Header {


    @JSONField(
            name = "IMEI"
    )
    public String getIMEI(JSONObject jsonObject) {
        String s = jsonObject.getString("IMEI");
        StringBuffer sb = new StringBuffer(s);
        while (sb.length() < 16) {
            sb.insert(0, "0");
        }
        return sb.toString();
    }

    @JSONField(
            name = "DeviceType"
    )
    public String getDeviceType(JSONObject jsonObject) {
        String deviceType = jsonObject.getString("DeviceType");
        return StringUtil.padZeroesToTheLeft(deviceType, 4);
    }

    @JSONField(
            name = "ProtocolVersion"
    )
    public String getProtocolVersion(JSONObject jsonObject) {
        Integer protocolVersion = jsonObject.getInteger("ProtocolVersion");
        return HexUtils.intToHex(protocolVersion, 4);
    }

    @JSONField(
            name = "CustomVersion"
    )
    public String getCustomVersion(JSONObject jsonObject) {
        Integer deviceType = jsonObject.getInteger("CustomVersion");
        return HexUtils.intToHex(deviceType, 2);
    }
}
